<?php

namespace app\common\model;

use app\common\model\BaseModel;


class PlatformLog extends BaseModel
{

    // 表名
    protected $name = 'platform_log';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'createtime_text',
        'order_type_text',
        'type_text',
    ];

    public function getCreatetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['createtime']) ? $data['createtime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }
    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : 1);
        return is_numeric($value) ? self::fetchOrderType($value) : $value;
    }
    public function getOrderTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['order_type']) ? $data['order_type'] : 1);
        return is_numeric($value) ? self::fetchOrderType($value) : $value;
    }

    public function user(){
        return $this->hasOne('user', 'id', 'user_id');
    }

    public function merchant(){
        return $this->hasOne('merchant', 'id', 'user_id');
    }

    //类型
    public static function fetchType($status = null){
        $data =  [
            1 => '订单支付',
            2 => '商家提现',
            3 => '订单退款',
            4 => '押金退款',
            5 => '用户提现',
            6 => '换车订单支付',
            7 => '换车订单退款',
            8 => '续租订单支付',
            9 => '续租订单退款',
            10 => '当面付款订单支付',
            11 => '当面付款订单退款',
            12 => '换车主订单退款',
            13 => '续租订单押金退款',
            14 => '换车总退款',
        ];
        if (isset($data[$status])) {
            return $data[$status];
        }else{
            return $data;
        }
    }
    //订单类型
    public static function fetchOrderType($status = null){
        $data =  [
            1 => '用户',
            2 => '商家',
        ];
        if (isset($data[$status])) {
            return $data[$status];
        }else{
            return $data;
        }
    }
}
